/*
*
*/
var vipMoney = 0.0;
var app = {
    addHandler: function (element, type, handler) { //绑定事件
        if (element.addEventListener) {
            element.addEventListener(type, handler, false);
        } else if (element.attachEvent) {
            element.attachEvent("on" + type, handler);
        } else {
            element["on" + type] = handler;
        }
    },
    browser: function () { //判断浏览器
        var ua = navigator.userAgent.toLocaleLowerCase();
        if(ua.match(/rv:([\d.]+)\) like gecko/) || ua.match(/msie ([\d.]+)/)) {
            return "ie";
        }else if (ua.match(/firefox\/([\d.]+)/)) {
            return "firefox";
        }else if (ua.match(/opera.([\d.]+)/)) {
            return "opera";
        }else if (ua.match(/applewebkit.*mobile.*/)||ua.match(/mpplewebkit/)){
        	return "mobile";
        }else if(ua.match(/\(i[^;]+;( u;)? cpu.+mac os x/)){
        	return "ios"
        }else if(ua.indexOf('android') > -1 || ua.indexOf('linux') > -1){
        	return "android";
        }else if(ua.indexOf('iphone') > -1 || ua.indexOf('mac') > -1){
        	return "iphone";
        }else if(ua.indexOf('ipad') > -1){
        	return "ipad";
        }else if (ua.match(/chrome\/([\d.]+)/)){
            return "chrome";
        }
    },
    getViewport: function () {
        if (document.compatMode == "BackCompat") {
            return {
                width: document.body.clientWidth,
                height: document.body.clientHeight
            }
        } else {
            return {
                width: document.documentElement.clientWidth,
                height: document.documentElement.clientHeight
            }
        }
    },
    popping: function (id, boolean) { //弹出层
        try {
            var pop_obj = document.getElementById(id);
            pop_obj.style.display = "block";
            var pop_obj_h = pop_obj.offsetHeight,
                pop_obj_w = pop_obj.offsetWidth;
            if (boolean) { //设置遮罩
                mask = document.createElement("div");
                mask.id = "mask";
                mask.style.top = 0 + "px";
                mask.style.left = 0 + "px";
                mask.style.height = document.body.offsetHeight + "px";
                mask.style.width = "auto";
                document.body.appendChild(mask);
				var that=this;
				//this.addHandler(mask,"click",function(){that.closed(id)});
				if (!window.XMLHttpRequest) {
					mask.style.height = document.body.clientHeight;
				}
               
            };
			var that=this;
            function init() { //弹出初始化位置
                if (document.documentElement.clientHeight - pop_obj_h > 0 && document.documentElement.clientWidth - pop_obj_w > 0) {
                    if (that.browser() == 'chrome' || that.browser() == 'safari') {
                        pop_obj.style.top = ((document.documentElement.clientHeight - pop_obj_h) / 2) + document.body.scrollTop / 2 + "px";
                    } else {
                        pop_obj.style.top = ((document.documentElement.clientHeight - pop_obj_h) / 2) + document.body.scrollTop / 2 + "px";
                    };
                }else{
					pop_obj.style.top = "10px";
				}
            }
            init();
            this.addHandler(window, "resize", function () {
                init();
            });
        } catch (e) {
            ///
        }
    },
    closed: function (id) { //关闭弹出层
        tar = document.getElementById(id);
        tar.style.display = "none";
        if (typeof mask !== 'undefined') {
            document.body.removeChild(document.getElementById("mask"));
        }
        if (typeof iframe !== 'undefined') {
            document.body.removeChild(document.getElementById("iframeMask"));
        }
    }
};

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return decodeURI((r[2]));
    return null; //返回参数值
}

function CompareDate(d1,d2)
{
    return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}

//关闭弹出窗口
function closeWin(id){
	var id = id;
	app.closed(id);
}
//弹出窗口
function openWin(id){
	var id = id;
	app.popping(id,true);
}

function RSA(value) {
    if (value == null || value == '' || value == undefined || value == 'undefined'){
        return null;
    }
    var publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQDmxMoxG+jbtgU+i06PjSVp7fmwuUveEsz/LQ8mIMFLAkHRWtZzeiDA8j9k0nUylEjo1xLXq3GJzFO7nbREdMmUWHS7bakQIig2CFLCtkJagw628smQ2tscz6Gv8AC+1nY9dC5Mc95fp9gVEj/a6bjfIIUWpi1ZyBbfb8qavyoQIDAQAB";
    var crypt = new JSEncrypt();
    crypt.setPublicKey(publicKey);
    return crypt.encrypt(value);
}